/*************************************************
Author: will
Date: 9/11/2012
Description:
Notes: 
*************************************************/

#ifndef __CTaskStatus_h__
#define __CTaskStatus_h__

#include "CTArray.h"
#include "CTaskDef.h"
#include "CTaskID.h"

class CUserTask;
class CTaskStatus
{
    friend class CUserTask;
public:
	CTaskStatus() 
        :_uiMainTaskStatus(0)
    {
	}

	virtual ~CTaskStatus() 
    {
	}

    void Clear()
    {
        _uiMainTaskStatus = 0;
        _astBranchTaskStatus.Clear();
    }

    int Init(CTaskStatusData& stData)
    {
        Clear();
        _uiMainTaskStatus = stData._uiMainTaskStatus;
        _astBranchTaskStatus = stData._astBranchTaskStatus;
        return 0;
    }

    int GetData(CTaskStatusData& stData)
    {
        stData.Clear();
        stData._uiMainTaskStatus = _uiMainTaskStatus;
        stData._astBranchTaskStatus = _astBranchTaskStatus;

        return 0;
    }

    int SetTaskFinished(CTaskID& stTaskID);

    bool IsFinished(CTaskID& stTaskID)
    {
        CT_TRACE(("检查任务是否已经完成："));
        stTaskID.DumpTaskID();

        if (stTaskID.IsMainTask())
        {
            CT_TRACE(("主线任务历史: %u", _uiMainTaskStatus));
            return _uiMainTaskStatus >= stTaskID._uiTaskID;
        }
        else
        {
            CT_TRACE(("当前支线ID %u, 历史 %u", stTaskID._uiBranchID, _astBranchTaskStatus[stTaskID._uiBranchID]));
            return (_astBranchTaskStatus.Size() > (int)stTaskID._uiBranchID 
                && _astBranchTaskStatus[stTaskID._uiBranchID] >= stTaskID._uiTaskID);
        }
    }

public:
	unsigned int                                    _uiMainTaskStatus;         //主线任务历史
    CTLib::CTArray<unsigned char, MAX_TASK_BRANCHS> _astBranchTaskStatus;      //分支任务历史
};


#endif // __CTaskStatus_h__

